import vnode from './vnode'

import createElement from './createElement'

import patchVnode from './patchVnode'

export default function (oldVnode, newVnode) {
    if (oldVnode.sel == undefined) {
        oldVnode = vnode(
            oldVnode.tagName.toLowerCase(),
            {},
            [],
            undefined,
            oldVnode
        )
    }

    if (oldVnode.sel == newVnode.sel) {
        console.log(oldVnode,111);
        patchVnode(oldVnode, newVnode)
    } else {
        let newVnodeElm = createElement(newVnode);
        let oldVnodeElm = oldVnode.elm;
        newVnodeElm ? oldVnodeElm.parentNode.insertBefore(newVnodeElm, oldVnodeElm) : undefined
        oldVnodeElm.parentNode.removeChild(oldVnodeElm)
    }
}